<template>
  <div class="switchItemBox">
    <div class="switchItemText">
      {{ projectName }}
    </div>
    <div class="switchItemIcon" @mouseover="() => { switchItemIcon = true }" @mouseleave="() => { switchItemIcon = false }"
      @click="() => { visible = true }">
      <Image :preview="false" :src=" switchItemIcon ? handOf_icon2 : handOf_icon"></Image>
    </div>
  </div>
  <Modal v-model:visible="visible" destroyOnClose title="选择项目" :footer="null" :width="1100">
    <div v-if="data?.length <= 3" class="projectSelectBox">
      <div class="List" v-for="(item, index) in data" @click="confirmProject(item)" @mouseenter="mouseenter(item, index)">
        <div class="title">{{ item.projectName }}</div>
        <div class="informBox">
          <div class="info" style="margin-right: 24px;">
            <div class="img">
              <Image :preview="false" :src="projectSelect01"></Image>
            </div>
            <div class="textBox">
              <div class="titleInfo">飞行总架次</div>
              <div class="text">{{ item.totalFlightSorties }} 次</div>
            </div>
          </div>

          <div class="info">
            <div class="img">
              <Image :preview="false" :src="projectSelect02"></Image>
            </div>
            <div class="textBox">
              <div class="titleInfo">飞行总时长</div>
              <div class="text">{{ item.totalFlightTime }} h</div>
            </div>
          </div>
        </div>
        <div class="dataChartBox">
          <div class="left">
            <div class="infoBox" style="margin-bottom: 20px;">
              <div class="img">
                <Image :preview="false" :src="projectSelect06"></Image>
              </div>
              <div class="number">
                {{ item.videoNum }}
              </div>
            </div>

            <div class="infoBox">
              <div class="img">
                <Image :preview="false" :src="projectSelect07"></Image>
              </div>
              <div class="number">
                {{ item.imgNum }}
              </div>
            </div>
          </div>
          <div class="right">
            <Bar width="132px" height="206px" :option="chartConfigure" :chartData="item.chartData"></Bar>
          </div>
        </div>
        <div class="cameraInformBox">
          <div class="BoxInfo">
            <div class="cameraInform" style="margin-right: 20px;">
              <div class="img">
                <Image :preview="false" :src="projectSelect05"></Image>
              </div>
              <div class="cameraInformText">全景图</div>
              <div class="cameraInformNumber">{{ item.panoramaNum }}</div>
            </div>

            <div class="cameraInform">
              <div class="img">
                <Image :preview="false" :src="projectSelect04"></Image>
              </div>
              <div class="cameraInformText">倾斜摄影</div>
              <div class="cameraInformNumber">{{ item.obliquePhotographNum }}</div>
            </div>
          </div>

          <div class="cameraInform">
            <div class="img">
              <Image :preview="false" :src="projectSelect03"></Image>
            </div>
            <div class="cameraInformText">正射影像</div>
            <div class="cameraInformNumber">{{ item.positiveProjectiveImageNum }}</div>
          </div>
        </div>
      </div>
    </div>


    <div v-else class="projectSelectBoxTwo">
      <div class="List" v-for="(item, index) in data" @click="confirmProject(item)" @mouseenter="mouseenter(item, index)">
        <div class="title">{{ item.projectName }}</div>
        <div class="informBox">
          <div class="info" style="margin-right: 40px;">
            <div class="img">
              <Image :preview="false" :src="projectSelect01"></Image>
            </div>
            <div class="textBox">
              <div class="titleInfo">飞行总架次</div>
              <div class="text">{{ item.totalFlightSorties }} 次</div>
            </div>
          </div>

          <div class="info">
            <div class="img">
              <Image :preview="false" :src="projectSelect02"></Image>
            </div>
            <div class="textBox">
              <div class="titleInfo">飞行总时长</div>
              <div class="text">{{ item.totalFlightTime }} h</div>
            </div>
          </div>
        </div>
        <div class="dataChartBox">
          <div class="left">
            <div class="infoBox">
              <div class="img">
                <Image :preview="false" :src="projectSelect06"></Image>
              </div>
              <div class="number">
                {{ item.videoNum }}
              </div>
            </div>

            <div class="infoBox">
              <div class="img">
                <Image :preview="false" :src="projectSelect07"></Image>
              </div>
              <div class="number">
                {{ item.imgNum }}
              </div>
            </div>
          </div>
          <div class="right">
            <Bar width="137px" height="104px" :option="chartConfigure" :chartData="item.chartData"></Bar>
          </div>
        </div>
        <div class="cameraInformBox">

          <div class="cameraInform">
            <div class="img">
              <Image :preview="false" :src="projectSelect05"></Image>
            </div>
            <div class="cameraInformText">全景图</div>
            <div class="cameraInformNumber">{{ item.panoramaNum }}</div>
          </div>

          <div class="cameraInform">
            <div class="img">
              <Image :preview="false" :src="projectSelect04"></Image>
            </div>
            <div class="cameraInformText">倾斜摄影</div>
            <div class="cameraInformNumber">{{ item.obliquePhotographNum }}</div>
          </div>


          <div class="cameraInform">
            <div class="img">
              <Image :preview="false" :src="projectSelect03"></Image>
            </div>
            <div class="cameraInformText">正射影像</div>
            <div class="cameraInformNumber">{{ item.positiveProjectiveImageNum }}</div>
          </div>
        </div>
      </div>
    </div>
  </Modal>
</template>
<script lang="ts" setup>
import { ref, onMounted, h, watch } from 'vue';
import { selectProject, saveSysUserSet, querySysUserSetByUserId } from '/@/views/projectManage/projectManage/data.api';
import { Modal } from 'ant-design-vue';
import { Tooltip } from 'ant-design-vue';
import { ClusterOutlined, SmileOutlined } from '@ant-design/icons-vue';
import Bar from '/@/components/chart/Bar.vue';
import { DataDirNavigation } from '/@/constants/index'
import { Image, notification } from 'ant-design-vue';
import { useRoute, useRouter, onBeforeRouteEnter } from 'vue-router';
import projectSelect01 from '@/assets/icons/projectSelect/projectSelect01.svg';
import projectSelect02 from '@/assets/icons/projectSelect/projectSelect02.svg';
import projectSelect03 from '@/assets/icons/projectSelect/projectSelect03.svg';
import projectSelect04 from '@/assets/icons/projectSelect/projectSelect04.svg';
import projectSelect05 from '@/assets/icons/projectSelect/projectSelect05.svg';
import projectSelect06 from '@/assets/icons/projectSelect/projectSelect06.svg';
import projectSelect07 from '@/assets/icons/projectSelect/projectSelect07.svg';
import handOf_icon from '@/assets/icons/projectSelect/handOf_icon.svg';
import handOf_icon2 from '@/assets/icons/projectSelect/handOf_icon2.svg';

const router = useRouter();

const visible = ref<boolean>(false);
let data = ref()
let chartData = ref([
  {
    "name": "视频",
    "value": 50
  },
  {
    "name": "图片",
    "value": {
      value: 30,
      itemStyle: {
        borderColor: 'rgba(255, 231, 69, 0.6)', // 设置边框颜色
        borderWidth: 1, // 设置边框宽度
        borderRadius: [4, 4, 0, 0], // 上面两个角设置圆角半径
        color: {
          type: 'linear', // 指定渐变类型
          x: 0, // 渐变起点 x 坐标
          y: 0, // 渐变起点 y 坐标
          x2: 0, // 渐变终点 x 坐标
          y2: 1, // 渐变终点 y 坐标
          colorStops: [
            {
              offset: 0, color: '#beba54' // 渐变起点颜色
            },
            {
              offset: 1, color: '#7a8b64' // 渐变终点颜色
            }
          ],
        },
      }
    }
  }
])

let projectName = ref() //显示项目名称
let switchItemIcon = ref(false) //

const chartConfigure = {
  yAxis: {
    show: false, // 将左边的Y轴隐藏
  },
  series: [
    {
      // name: '示例数据',
      type: 'bar',
      label: {
        show: true, // 启用标签显示
        position: 'top', // 位置可以是 'top'、'insideTop'、'inside' 等
      },
      itemStyle: {
        borderColor: 'rgba(80,252,255,0.6)', // 设置边框颜色
        borderWidth: 1, // 设置边框宽度
        borderRadius: [4, 4, 0, 0], // 上面两个角设置圆角半径
        color: {
          type: 'linear', // 指定渐变类型
          x: 0, // 渐变起点 x 坐标
          y: 0, // 渐变起点 y 坐标
          x2: 0, // 渐变终点 x 坐标
          y2: 1, // 渐变终点 y 坐标
          colorStops: [
            {
              offset: 0, color: '#4ac4cd' // 渐变起点颜色
            },
            {
              offset: 1, color: '#4a959b' // 渐变终点颜色
            }
          ],
        },
      },
    },
  ]
}

function mouseenter(item, index) {
  let a = item.chartData[0].value
  let b = item.chartData[1].value.value
  console.log(item, index)
  data.value[index].chartData[0].value = 0
  data.value[index].chartData[1].value.value = 0
  data.value[index].chartData[0].value = a
  data.value[index].chartData[1].value.value = b

}

async function confirmProject(item) {
  await saveSysUserSet({
    userId: localStorage.getItem('userId'),
    type: 0,
    id: localStorage.getItem('configure_Id'),  // 这里的id 是配置id
    content: item.id //这个id 是项目id
  })
  localStorage.setItem('Project_Id', item.id);
  const myArray = [item.longitude, item.latitude]
  localStorage.setItem('latitudeLongitude', JSON.stringify(myArray))
  projectName.value = item.projectName
  notification.open({
    message: '项目切换成功',
    description: `当前项目为：${item.projectName}`,
    icon: () => h(SmileOutlined, { style: 'color: #15B37A' }),
  });
  visible.value = false
  sessionStorage.setItem(DataDirNavigation, '')  // 切换项目时清空数据管理列表页的目录路径缓存
  router.go(0)
}

watch(
  () => visible.value,
  (newValue) => {
    if (newValue) {
      getData()
    }
    console.log(newValue)
  }
)

async function getData() {
  data.value = await selectProject({ userId: localStorage.getItem('userId') })
  console.log(data.value, 'datavalue')
  data.value = data.value.map((item) => {
    if (localStorage.getItem('Project_Id') && localStorage.getItem('Project_Id') == item.id) {
      projectName.value = item.projectName
    }
    return {
      ...item,
      chartData: [
        {
          "name": "视频",
          "value": item.videoNum,
          // "value": 50,
        },
        {
          "name": "图片",
          "value": {
            value: item.imgNum,
            // value: 30,
            itemStyle: {
              borderColor: 'rgba(255, 231, 69, 0.6)', // 设置边框颜色
              borderWidth: 1, // 设置边框宽度
              borderRadius: [4, 4, 0, 0], // 上面两个角设置圆角半径
              color: {
                type: 'linear', // 指定渐变类型
                x: 0, // 渐变起点 x 坐标
                y: 0, // 渐变起点 y 坐标
                x2: 0, // 渐变终点 x 坐标
                y2: 1, // 渐变终点 y 坐标
                colorStops: [
                  {
                    offset: 0, color: '#beba54' // 渐变起点颜色
                  },
                  {
                    offset: 1, color: '#7a8b64' // 渐变终点颜色
                  }
                ],
              },
            }
          }
        }
      ]
    }
  })
}

// getData()
onMounted(async () => {
  getData()
})

</script>
<style lang="less" scoped>
.switchItemBox {
  height: 32px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  border-radius: 9px;
  margin-left: 11px;

  .switchItemText {
    font-size: 16px;
    color: #FFFFFF;
  }

  .switchItemIcon {
    display: none;
    cursor: pointer;
  }
}

.switchItemBox:hover {
  background-color: #094467;

  .switchItemIcon {
    display: block;
  }
}

.projectSelectBox {
  height: 700px;
  background: url("@/assets/icons/projectSelect/projectSelectBG.jpg") no-repeat center;
  padding: 0 57px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 30px;

  .List {
    background: rgba(147, 181, 194, 0.1);
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    backdrop-filter: blur(10px);
    display: inline-block;

    .title {
      font-weight: 500;
      color: #FFFFFF;
      font-size: 18px;
      text-align: center;
      margin-top: 24px;
    }

    .informBox {
      display: flex;
      align-items: center;
      margin-top: 44px;
      padding: 0 21px;
      margin-bottom: 24px;

      .info {
        display: flex;
        align-items: center;

        .img {
          width: 40px;
          height: 40px;
          // background-color: aqua;
          margin-right: 13px;
        }

        .textBox {
          .titleInfo {
            font-size: 12px;
            font-weight: 400;
            color: #FFFFFF;
          }

          .text {
            font-size: 16px;
            font-weight: 500;
            color: #FFFFFF;
          }
        }
      }

    }

    .dataChartBox {
      background: rgba(147, 181, 194, 0.1);
      border-radius: 4px;
      margin-left: 16px;
      margin-right: 16px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 20px 0 28px;
      margin-bottom: 26px;

      .left {
        .infoBox {
          display: flex;
          align-items: center;

          .img {
            margin-right: 23px;
            width: 27px;
            height: 27px;

            .icon {
              font-size: 34px;
              color: #3d9dc4;

            }
          }

          .number {
            font-size: 20px;
            font-weight: 500;
            color: #FFFFFF;
          }
        }
      }

      .right {}
    }

    .cameraInformBox {
      padding: 0 14px 0 15px;
      margin-bottom: 60px;

      // padding-left: 31px;
      .BoxInfo {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 23px;
      }

      .cameraInform {
        display: flex;
        align-items: center;

        .img {
          width: 30px;
          height: 30px;
          margin-right: 12px;
        }

        .cameraInformText {
          font-size: 14px;
          font-weight: 400;
          color: #FFFFFF;
          width: 66px;
          margin-right: 12px;
        }

        .cameraInformNumber {
          font-size: 14px;
          font-weight: 400;
          color: #FFFFFF;
        }
      }
    }
  }

  .List:hover {
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.15);
    border: 1px solid #8eb8c9;
    backdrop-filter: blur(10px);
    // transition: 0.5s ease;
  }
}

.projectSelectBoxTwo {
  height: 700px;
  background: url("@/assets/icons/projectSelect/projectSelectBG.jpg") no-repeat center;
  padding: 26px 57px;

  gap: 30px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow-x: hidden;
  overflow-y: auto;


  .List {
    background: rgba(147, 181, 194, 0.1);
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    backdrop-filter: blur(10px);
    display: inline-block;
    width: 314px;

    .title {
      font-weight: 500;
      color: #FFFFFF;
      font-size: 18px;
      text-align: center;
      margin-top: 16px;
    }

    .informBox {
      display: flex;
      align-items: center;
      margin-top: 28px;
      padding: 0 21px;
      margin-bottom: 24px;

      .info {
        display: flex;
        align-items: center;

        .img {
          width: 40px;
          height: 40px;
          // background-color: aqua;
          margin-right: 11px;
        }

        .textBox {
          .titleInfo {
            font-size: 12px;
            font-weight: 400;
            color: #FFFFFF;
          }

          .text {
            font-size: 16px;
            font-weight: 500;
            color: #FFFFFF;
          }
        }
      }

    }

    .dataChartBox {
      background: rgba(147, 181, 194, 0.1);
      border-radius: 4px;
      margin-left: 16px;
      margin-right: 16px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 20px 0 28px;
      margin-bottom: 17px;

      .left {
        .infoBox {
          display: flex;
          align-items: center;

          .img {
            margin-right: 23px;
            width: 27px;
            height: 27px;

            .icon {
              font-size: 34px;
              color: #3d9dc4;

            }
          }

          .number {
            font-size: 20px;
            font-weight: 500;
            color: #FFFFFF;
          }
        }
      }

      .right {}
    }

    .cameraInformBox {
      padding: 0 14px 0 15px;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .cameraInform {
        display: flex;
        align-items: center;

        .img {
          width: 23px;
          height: 23px;
          margin-right: 7px;
        }

        .cameraInformText {
          font-size: 12px;
          font-weight: 400;
          color: #FFFFFF;
          margin-right: 5px;
        }

        .cameraInformNumber {
          font-size: 14px;
          font-weight: 400;
          color: #FFFFFF;
        }
      }
    }
  }

  .List:hover {
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.15);
    border: 1px solid #8eb8c9;
    backdrop-filter: blur(10px);
    // transition: 0.5s ease;
  }
}

.p-1 {
  span {}
}

.jeecg-layout-header-action__item {}
</style>
